<template>
    <view class="password">
        <u-form class="password-form" :model="form" ref="form" :error-type="['toast']">
            <u-form-item class="password-form_item" prop="email" left-icon="email" :left-icon-style="iconStyle">
                <u-input v-model="form.Email" :placeholder="$t('mine.input_new_email')"/>
            </u-form-item>
        </u-form>
        <view class="password-button">
            <u-button type="primary" @click="submit">{{$t('mine.btn_save')}}</u-button>
        </view>
    </view>
</template>

<script>
import pageMixin from '@/utils/pageMixin';
export default {
  mixins: [pageMixin],
		data() {
			return {
				form: {
						Email: '',
				},
				iconStyle: {
						fontSize: '38rpx',
						color: '#646466',
						display: 'flex'
				},
				rules: {
						Email: [
								{
										required: true,
										message: this.$t('mine.msg_email'),
										type: 'email'
								}
						],
				},
				seconds: 60,
			}
		},

		onLoad() {
		},
		onShow() {
		},
		onReady() {
				this.$refs.form.setRules(this.rules);
		},
		components: {
		},
		computed: {
			i18n(){
				return this.$t('mine')
			}
		},
		methods: {
      codeChange(text) {
				this.tips = text;
			},
      submit() {
				let that = this;
				this.$refs.form.validate(valid => {
						if (valid) {
						let data = {
							email: this.form.Email,
						};
						this.$http.post('/client/user/account/email/modify', data).then(res => {
							uni.showToast({
								title: this.$t('mine.save_success')
							});
							setTimeout(function () {
								that.$u.route({
									type: 'switchTab',
									url: '/pages/mine/index'
								});
							}, 1000);
						});
							} else {
									console.log('验证失败');
							}
					});
			}
		}
	}
</script>

<style lang="scss" scoped>
    .password {
        height: 100vh;
        background-color: #ffffff;
    }
    .password-form {
        padding: 0 30rpx;
        margin-bottom: 60rpx;
    }
    .password-button {
        padding: 0 80rpx;
    }
</style>
